@瞌睡虫
3年前 提问
1个回答

linux如何开启日志审计

GQQQy
3年前

linux开启日志审计功能需要修改/etc/profile这个配置文件,再其末尾添加内容(内容较多放在下方)后执行source /etc/profile使之生效。

HISTSIZE=1000

HISTTIMEFORMAT="%Y/%m/%d %T ";export HISTTIMEFORMAT

export HISTORY_FILE=/var/log/audit.log

export PROMPT_COMMAND='{ thisHistID=`history 1|awk "{print \\$1}"`;lastCommand=`history 1| awk "{\\$1=\"\" ;print}"`;user=`id -un`;whoStr=(`who -u am i`);realUser=${whoStr[0]};logMonth=${whoStr[2]};logDay=${whoStr[3]};pid=${whoStr[6]};ip=${whoStr[7]};if [ ${thisHistID}x != ${lastHistID}x ];then echo -E `date "+%Y/%m/%d %H:%M:%S"` $user$realUser
@$ip[IP:$pid][LOGIN:$logMonth $logDay] --- $lastCommand ;lastHistID=$thisHistID;fi; } >> $HISTORY_FILE'